#include "SEL.h"

using namespace SEL;

// Dummy class that only writes messages.
class MyRWops : public RWops
{
public:
	MyRWops ()
	{
		std::cout << "MyRWops::MyRWops ()" << std::endl;
	}
	
	virtual ~MyRWops ()
	{
		std::cout << "MyRWops::~MyRWops ()" << std::endl;
		close ();
	}
	
	virtual int doSeek (int offset, int whence)
	{
		std::cout << "Seeking to " << offset << ", whence = " << whence
		     << std::endl;
		return 1;
	}
	
	virtual int doRead (void *ptr, int size, int maxnum)
	{
		std::cout << "Reading - size: " << size << ", maxnum: " << maxnum
		     << std::endl;
		return maxnum;
	}
	
	virtual int doWrite (const void *ptr, int size, int num)
	{
		std::cout << "Writing - size: " << size << ", num: " << num
		     << std::endl;
		return num;
	}	
	
	virtual int doClose ()
	{
		std::cout << "Closing" << std::endl;
		return 1;
	}
};

int main (int argc, char **argv)
{
	debug::init (true);
	
	std::cout << std::endl << "Manual closing..." << std::endl << std::endl;
	
	MyRWops *rw = new MyRWops ();
	rw->seek (100, SEEK_SET);
	rw->read (NULL, 10, 100);
	rw->write (NULL, 10, 100);
	rw->close ();
	delete rw;

	std::cout << std::endl << "Auto closing..." << std::endl << std::endl;
	
	rw = new MyRWops ();
	rw->seek (100, SEEK_SET);
	rw->read (NULL, 10, 100);
	rw->write (NULL, 10, 100);
	delete rw;

	return 0;
}
